#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:6031)

#include <stdio.h>

typedef struct Node
{
    int val;
    struct Node* next;
}Node;

Node* CreateList(int n)
{
    Node* phead = (Node*)malloc(sizeof(Node));
    phead->val = 1;
    phead->next = NULL;
    Node* ptail = phead;

    for (int i = 2; i <= n; i++)
    {
        Node* newnode = (Node*)malloc(sizeof(Node));
        newnode->val = i;
        newnode->next = NULL;
        ptail->next = newnode;
        ptail = newnode;

    }

    ptail->next = phead;

    return ptail;
}

int main()
{
    // write code here
    Node* prev = CreateList(2);
    Node* pcur = prev->next;
    int count = 1;

    while (pcur != pcur->next)
    {
        if (count == 1)
        {
            prev->next = pcur->next;
            free(pcur);
            pcur = prev->next;
            count = 1;
        }
        else
        {
            prev = pcur;
            pcur = pcur->next;
            count++;
        }
    }

    printf("%d", pcur->val);

    return 0;
}